/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CompanyInfo;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.TagManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class AddTag extends AbstractAction
/*    */ {
/* 23 */   private static Logger logger = Logger.getLogger(AddTag.class.getName());
/*    */ 
/*    */   public AddTag(AbstractHttpServlet servlet) {
/* 26 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException
/*    */   {
/* 33 */     response.setContentType("text/html;charset=utf-8");
/* 34 */     PrintWriter out = response.getWriter();
/* 35 */     JSONObject jsonObject = new JSONObject();
/*    */ 
/* 37 */     User loginUser = super.getLoginUser(request);
/*    */ 
/* 39 */     if (!loginUser.isAdmin) {
/* 40 */       jsonObject.put("error", "0");
/* 41 */       out.println(jsonObject);
/* 42 */       out.flush();
/* 43 */       out.close();
/* 44 */       return;
/*    */     }
/*    */ 
/* 47 */     String tagName = request.getParameter("TagName");
/*    */ 
/* 49 */     String userId = loginUser.userId;
/* 50 */     int companyId = loginUser.companyId;
/* 51 */     TagManager manager = new TagManager();
/*    */     try {
/* 53 */       int tagId = manager.add(tagName, companyId, userId);
/* 54 */       jsonObject.put("error", "0");
/* 55 */       jsonObject.put("tagId", Integer.valueOf(tagId));
/*    */ 
/* 58 */       CompanyInfo company = super.getCompany(companyId);
/*    */       try {
/* 60 */         company.tags = manager.list(companyId);
/*    */       } catch (DBException e) {
/* 62 */         logger.warn("get all tags failed", e);
/*    */       }
/*    */     }
/*    */     catch (DBException e) {
/* 66 */       jsonObject.put("error", "1");
/* 67 */       logger.warn("add tag failed", e);
/*    */     }
/* 69 */     out.println(jsonObject);
/* 70 */     out.flush();
/* 71 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddTag
 * JD-Core Version:    0.6.1
 */